package com.memo4android.model;

import com.memo4android.ui.FolderButton;
import com.memo4android.ui.FolderClikedListener;
import com.memo4android.ui.FolderLongClikedListener;
import com.memo4android.ui.NoteButton;
import com.memo4android.ui.NoteClickedListener;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.GridView;

public class AllNotesAdapter extends BaseAdapter {

	private Context mContext;
	private AppModel model;

    public AllNotesAdapter(Context c) {
    	mContext = c;
        model = AppModel.getInstance(c);
    }


	public int getCount() {
		return model.getNumberOfDossiers() + model.getHome().getNumberOfNotes();
	}

	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		if(position < model.getNumberOfDossiers()){
			//Il s'agit d'un dossier
			Dossier dossier = model.getDossier(position);
			FolderButton folderButton = new FolderButton(mContext, dossier);
			folderButton.setOnClickListener(new FolderClikedListener(mContext, dossier));
			folderButton.setOnLongClickListener(new FolderLongClikedListener(mContext, dossier));
			folderButton.setLayoutParams(new GridView.LayoutParams(LayoutParams.FILL_PARENT, 70));
			return folderButton;
		} else {
			//Il s'agit des notes de HOME
			int i = model.getNumberOfDossiers();
			ItemNote note = model.getHome().getNote(position - i);
			NoteButton noteButton = new NoteButton(mContext, note);
			noteButton.setOnClickListener(new NoteClickedListener(mContext, note));
			noteButton.setLayoutParams(new GridView.LayoutParams(LayoutParams.FILL_PARENT, 70));
			return noteButton;
		}
	}

}
